package com.richrail.gui;

import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;

import com.richrail.Depot;
import com.richrail.console.CLI;
import com.richrail.console.ClojureExecutor;
import com.richrail.state.ClojureStateProvider;

public class GUI
{
	public static void main(String[] args)
	{
		SwingUtilities.invokeLater(new Runnable() 
		{
			@Override
			public void run() 
			{
				// Initialize the depot.
				Depot depot = new Depot();
				//DepotStorage depotStorage = new DepotStorage(depot);
				depot.setStateProvider(new ClojureStateProvider());
				
				// Create the CLI. The GUI passes their calls through the CLI,
				// so they do not directly access the domain model side.
				CLI cli = new CLI(new ClojureExecutor());
				
				// The TabbedDisplay component manages the displays,
				// but the displays could also be used outside TabbedDisplay if necessary.
				TabbedView.setDepot(depot);
				TabbedView.addView(GraphicView.class);
				TabbedView.addView(TextView.class);
				
				// Create two windows. One containing the console and the other the old graphical interface.
				{
					ConsoleWindow consoleView = new ConsoleWindow(cli);
					cli.addResponseListener(consoleView);
					{
						JFrame frame = new JFrame();
						frame.getContentPane().add(consoleView);
						frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
						frame.pack();
						frame.setVisible(true);
					}
				}
				{
					GraphicWindow graphicView = new GraphicWindow(cli);
					depot.attachObserver(graphicView);
					{
						JFrame frame = new JFrame();
						frame.getContentPane().add(graphicView);
						frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
						frame.pack();
						frame.setVisible(true);
					}
				}
			}
		});
	}
}
